<?php


namespace App\Utility\Queue;


use App\Crontab\GuessTask;
use App\Crontab\MessageTask;
use App\Crontab\OrderTask;
use EasySwoole\Component\Process\AbstractProcess;
use EasySwoole\Queue\Job;


class QueueProcess extends AbstractProcess
{
    protected function run($arg)
    {

        // TODO: Implement run() method.
        Queue::getInstance()->consumer()->listen(function (Job $job) {
            //接收到一条消息
            echo('接到JOB类型为：' . $job->getJobData()['type'] . PHP_EOL);

            //判断信息的TYPE
            if ($job->getJobData()['type'] == QueueType::MESSAGE_APPOINTMEMT_1) {
                MessageTask::consumer($job->getJobData()['list']);
                return;
            }

            //判断信息的TYPE
            if ($job->getJobData()['type'] == QueueType::MESSAGE_APPOINTMEMT_2) {
                MessageTask::consumer2($job->getJobData()['list']);
                return;
            }
            //判断信息的TYPE
            if ($job->getJobData()['type'] == QueueType::MESSAGE_APPOINTMEMT_3) {
                MessageTask::consumer3($job->getJobData()['list']);
                return;
            }
            //判断信息的TYPE
            if ($job->getJobData()['type'] == QueueType::MESSAGE_APPOINTMEMT_4) {
                MessageTask::consumer4($job->getJobData()['list']);
                return;
            }

            if ($job->getJobData()['type'] == QueueType::MESSAGE_SUMBIT_ORDER) {
                OrderTask::consumer_sumbit($job->getJobData()['list']);
                return;
            }
            if ($job->getJobData()['type'] == QueueType::MESSAGE_VERIFY_ORDER) {
                OrderTask::consumer_verify($job->getJobData()['list']);
                return;
            }

            if ($job->getJobData()['type'] == QueueType::MESSAGE_GUESS_SUCCESS) {
                GuessTask::consumer_success($job->getJobData()['list']);
                return;
            }

            if ($job->getJobData()['type'] == QueueType::MESSAGE_GUESS_FAIL) {
                GuessTask::consumer_fail($job->getJobData()['list']);
                return;
            }

        });
    }

    protected function onShutDown()
    {
        Queue::getInstance()->consumer()->stopListen();
    }


}